﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraEditors;
using System.Windows.Forms;
using SMS.Magus;
using System.Diagnostics;
using System.IO;

namespace SmsUI
{
    public class FormManager
    {
        public static FormManager Instance = new FormManager();
        public MainForm MainForm { get; set; }
        public ProcessingForm ProcessForm { get; set; }
        Dictionary<string, XtraUserControl> userControlDic = new Dictionary<string, XtraUserControl>();

        public Dictionary<string, XtraUserControl> UserControlDic
        {
            get { return userControlDic; }
            set { userControlDic = value; }
        }
        public void InitForm()
        {
          
            SetManagerForm setManagerItem = new SetManagerForm();
            setManagerItem.Dock = DockStyle.Fill;
            userControlDic.Add("SetManagerItem", setManagerItem);
           
            FirstForm firstItem = new FirstForm();
            firstItem.Dock = DockStyle.Fill;
            userControlDic.Add("FirstItem", firstItem);

            SendSMSForm smsForm = new SendSMSForm();
            firstItem.Dock = DockStyle.Fill;
            userControlDic.Add("SendContentItem", smsForm);

            sendListForm sendListForm = new sendListForm();
            sendListForm.Dock = DockStyle.Fill;
            userControlDic.Add("SendListItem", sendListForm);

            ReciveListForm recListForm = new ReciveListForm();
            sendListForm.Dock = DockStyle.Fill;
            userControlDic.Add("ReciveRecodItem", recListForm);

            SendedListForm sendedListForm = new SendedListForm();
            sendListForm.Dock = DockStyle.Fill;
            userControlDic.Add("SendRecodItem", sendedListForm);


            frmTrueTel frmTrueForm = new frmTrueTel();
            frmTrueForm.Dock = DockStyle.Fill;
            userControlDic.Add("TrueNumItem", frmTrueForm);

            frmAutoTel frmAutoTel = new frmAutoTel();
            frmAutoTel.Dock = DockStyle.Fill;
            userControlDic.Add("AutoTelItem", frmAutoTel);

        }
        public void ShowForm(string formName)
        {
            foreach (XtraUserControl uc in userControlDic.Values)
            {
                uc.Visible = false;
            }
            if (userControlDic.ContainsKey(formName))
            {
                if (formName == "AutoTelItem")
                {
                    try
                    {
                        string fileName = Path.Combine(Application.StartupPath, "MagicBox.exe");
                        Process.Start(fileName);
                    }
                    catch
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("启动号码魔方失败!");
                    }
                    return;
                }
                userControlDic[formName].Visible = true;
            }
        }

        public XtraUserControl GetForm(string formName)
        {
            if (userControlDic.ContainsKey(formName))
            {
                return userControlDic[formName];
            }
            return null;
        }
    }
}
